package com.deep.docker.gateway.controller;


import com.deep.docker.gateway.entity.ResultJson;
import com.deep.docker.gateway.entity.dto.LoginUserDTO;
import com.deep.docker.gateway.entity.vo.UserVO;
import com.deep.docker.gateway.service.LoginService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author Joetao
 * @time 2021/1/26 11:21 上午
 * @Email cutesimba@163.com
 */
@RequestMapping("/api/v1")
@RestController
public class LoginController {
    private final LoginService loginService;

    public LoginController(LoginService loginService) {
        this.loginService = loginService;
    }

    @PostMapping(value = "/login")
    public ResultJson<UserVO> login(@Valid @RequestBody LoginUserDTO user) {
        UserVO userVO = loginService.login(user.getUsername(), user.getPassword());
        return ResultJson.ok(userVO);
    }

    @PostMapping(value = "/logout")
    public ResultJson<Object> logout() {
        loginService.logout();
        return ResultJson.ok();
    }
}
